import request from "@/common/http";
import roleListResponse from './mock/roleList.json'
import menu_treeResponse from './mock/menu_tree.json'
import {Role} from "@/pages/system/user/constant";

export function apiGetRoleList(params: any, useMock?: boolean): Promise<any> {
  if (useMock) {
    return Promise.resolve(roleListResponse)
  }
  return request.get('/gateway/ums/sys-role', params)
}

export async function queryRole(params?: any) {
  return request('/api/sys/role/list', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

export async function queryMenuByRoleId(params: any, useMock?: boolean) {
  if (useMock) {
    return Promise.resolve(menu_treeResponse)
  }
  return request('/api/sys/role/queryMenuByRoleId', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

export async function updateRoleMenu(params: { roleId: number, menuIds: number[] }) {
  return request('/api/sys/role/updateRoleMenu', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

export async function removeRoleOne(params: { id: number }) {
  return request('/api/sys/role/delete', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

export async function removeRole(params: { ids: number[] }) {
  return request('/api/sys/role/delete', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

export async function addRole(params: Role) {
  return request('/api/sys/role/add', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

export async function updateRule(params: Role) {
  return request('/api/sys/role/update', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}
